<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"blog.tabcen.top","root":"/","images":"/images","scheme":"Pisces","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="本篇文章介绍游戏开发过程中如果将游戏开发工程化，像开发app一样开发游戏  技术选型 TypeScript 语言 cocos 引擎 CocosCreator、VSCode 开发工具  项目结构123456789101112131415161718192021222324252627&#x2F;animations      -- 动画资源    &#x2F;animation_anim    &amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="20200509-游戏开发框架搭建一">
<meta property="og:url" content="http://blog.tabcen.top/2020/05/09/%E6%B8%B8%E6%88%8F/20200509-cocos%E5%B0%8F%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%B3%BB%E5%88%97%E4%B8%80/index.html">
<meta property="og:site_name" content="TabCen&#39;s Blog">
<meta property="og:description" content="本篇文章介绍游戏开发过程中如果将游戏开发工程化，像开发app一样开发游戏  技术选型 TypeScript 语言 cocos 引擎 CocosCreator、VSCode 开发工具  项目结构123456789101112131415161718192021222324252627&#x2F;animations      -- 动画资源    &#x2F;animation_anim    &amp;">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-05-09T01:06:44.000Z">
<meta property="article:modified_time" content="2021-04-21T13:14:12.133Z">
<meta property="article:author" content="TabCen">
<meta property="article:tag" content="游戏">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://blog.tabcen.top/2020/05/09/%E6%B8%B8%E6%88%8F/20200509-cocos%E5%B0%8F%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%B3%BB%E5%88%97%E4%B8%80/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>20200509-游戏开发框架搭建一 | TabCen's Blog</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">TabCen's Blog</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">记录自己的学习过程</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section">首页</a></li>
        <li class="menu-item menu-item-前端"><a href="/categories/%E5%89%8D%E7%AB%AF/" rel="section">前端</a></li>
        <li class="menu-item menu-item-ios"><a href="/categories/iOS/" rel="section">iOS</a></li>
        <li class="menu-item menu-item-感想"><a href="/categories/%E6%84%9F%E6%83%B3/" rel="section">感想</a></li>
        <li class="menu-item menu-item-游戏"><a href="/categories/%E6%B8%B8%E6%88%8F/" rel="section">游戏</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section">归档</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section">标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger">搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B"><span class="nav-number">1.</span> <span class="nav-text">技术选型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84"><span class="nav-number">2.</span> <span class="nav-text">项目结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83"><span class="nav-number">3.</span> <span class="nav-text">命名规范</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%84%9A%E6%9C%AC%E8%A7%84%E8%8C%83"><span class="nav-number">4.</span> <span class="nav-text">脚本规范</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%84%9F%E6%83%B3"><span class="nav-number">5.</span> <span class="nav-text">感想</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">TabCen</p>
  <div class="site-description" itemprop="description">今日而言治术，则莫若综合名实；今日而言学术，则莫若取笃实践履之士。物穷则变，救浮华者莫若质。积翫之后，振之以猛，意在斯乎！</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/TabCen" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;TabCen" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:964267617@qq.com" title="E-Mail → mailto:964267617@qq.com" rel="noopener" target="_blank"><i class="envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/tabcen" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;tabcen" rel="noopener" target="_blank"><i class="weibo fa-fw"></i>Weibo</a>
      </span>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://blog.tabcen.top/2020/05/09/%E6%B8%B8%E6%88%8F/20200509-cocos%E5%B0%8F%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%B3%BB%E5%88%97%E4%B8%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="TabCen">
      <meta itemprop="description" content="今日而言治术，则莫若综合名实；今日而言学术，则莫若取笃实践履之士。物穷则变，救浮华者莫若质。积翫之后，振之以猛，意在斯乎！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="TabCen's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          20200509-游戏开发框架搭建一
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-05-09 09:06:44" itemprop="dateCreated datePublished" datetime="2020-05-09T09:06:44+08:00">2020-05-09</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-04-21 21:14:12" itemprop="dateModified" datetime="2021-04-21T21:14:12+08:00">2021-04-21</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E6%B8%B8%E6%88%8F/" itemprop="url" rel="index"><span itemprop="name">游戏</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <blockquote>
<p>本篇文章介绍游戏开发过程中如果将游戏开发工程化，像开发app一样开发游戏</p>
</blockquote>
<h2 id="技术选型"><a href="#技术选型" class="headerlink" title="技术选型"></a>技术选型</h2><ul>
<li>TypeScript 语言</li>
<li>cocos 引擎</li>
<li>CocosCreator、VSCode 开发工具</li>
</ul>
<h2 id="项目结构"><a href="#项目结构" class="headerlink" title="项目结构"></a>项目结构</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;animations      -- 动画资源</span><br><span class="line">    &#x2F;animation_anim</span><br><span class="line">    &#x2F;animation_prefab</span><br><span class="line">    &#x2F;animation_texture</span><br><span class="line">&#x2F;base</span><br><span class="line">    BaseScene.ts</span><br><span class="line">    BasePrefab.ts</span><br><span class="line">&#x2F;components      -- 公用组件 预制体、脚本</span><br><span class="line">    &#x2F;popup</span><br><span class="line">        basePopup.ts</span><br><span class="line">        popup.prefab</span><br><span class="line">    &#x2F;other</span><br><span class="line">&#x2F;resources       -- loadRes 动态加载</span><br><span class="line">&#x2F;scene</span><br><span class="line">    &#x2F;MainScene</span><br><span class="line">        MainScene.fire</span><br><span class="line">        MainScene.ts</span><br><span class="line">&#x2F;static</span><br><span class="line">    &#x2F;images          -- 图片资源</span><br><span class="line">    &#x2F;media           -- 媒体资源</span><br><span class="line">&#x2F;utils           -- 工具类</span><br><span class="line">    common.js</span><br><span class="line">    globalFunction.js</span><br><span class="line">    md5.js</span><br><span class="line">    &#x2F;api</span><br><span class="line">        token.js</span><br><span class="line">        http.js</span><br></pre></td></tr></table></figure>
<p>着重讲一下，抽离基类 BaseScene.ts、BasePrefab.ts，将一些相关方法封装到BaseScene.ts中，其他的场景均继承自基类。这样做的好处</p>
<ul>
<li>代码更加洁简</li>
<li>增加可重构性</li>
</ul>
<p><strong>注意</strong><br>不建议封装功能特别大、多的基类。这样增加了基类的耦合性。可将同类方法抽离成接口。再在不同的类中进行继承。仅仅是为了去重而写基类是不合理的</p>
<h2 id="命名规范"><a href="#命名规范" class="headerlink" title="命名规范"></a>命名规范</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">资源    icon_btn_1.jpg  短横线</span><br><span class="line">预制体  popup_prefab.prefab</span><br><span class="line">场景    MainScene 大驼峰</span><br><span class="line">脚本    小驼峰</span><br><span class="line">变量    小驼峰  </span><br><span class="line">    let timeScope &#x3D; 242342</span><br><span class="line">    let _this &#x3D; this</span><br><span class="line">    let _scope &#x3D; scope</span><br></pre></td></tr></table></figure>

<h2 id="脚本规范"><a href="#脚本规范" class="headerlink" title="脚本规范"></a>脚本规范</h2><ul>
<li>添加<code>MARK</code>标记</li>
<li>冗余代码删除</li>
<li>缩进 两个空格</li>
<li>onClick***</li>
<li>function 单一职责：一个方法，一个功能，解耦</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;&#x2F; MARK: 属性声明</span><br><span class="line">&#x2F;&#x2F;&#x2F; MARK: 生命周期函数</span><br><span class="line">&#x2F;&#x2F;&#x2F; MARK: 私有方法</span><br><span class="line">&#x2F;&#x2F;&#x2F; MARK: 网络请求</span><br><span class="line">    request_home()</span><br></pre></td></tr></table></figure>

<h2 id="感想"><a href="#感想" class="headerlink" title="感想"></a>感想</h2><p>虽未深入涉足游戏开发，但是感觉目前的游戏开发社区依然不够火热（可能是相较于其他开发领域）。游戏开发工程师可能在开发游戏的过程中忽略了游戏开发也属于一项软件工程。而软件工程架构设计和规范是值得思考的。游戏开发过程中不能仅仅关注游戏的界面。在这段时间使用cocoscreator开发小程序的过程中发现，大多数游戏开发工程师在进行游戏开发时，更多得使用可视化的拖控件功能。这种操作非常不够技术性。更加偏向于美工设计工作。我个人更加提倡游戏开发者应该将重点聚焦在逻辑实现和代码的架构方向。譬如，去了解MVC、去构建页面栈、多平台兼容等</p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E6%B8%B8%E6%88%8F/" rel="tag"># 游戏</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2020/04/22/%E5%89%8D%E7%AB%AF/20200422-webpack-bundle-loader/" rel="prev" title="webpack打包解析二">
                  <i class="fa fa-chevron-left"></i> webpack打包解析二
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2020/05/10/%E6%B8%B8%E6%88%8F/20200510-cocos%E5%B0%8F%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E7%B3%BB%E5%88%97%E4%BA%8C/" rel="next" title="20200510-cocos小游戏系列二">
                  20200510-cocos小游戏系列二 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">TabCen</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  
<script src="/js/local-search.js"></script>






  





</body>
</html>
